<?php

namespace App\Lib\Library;

class ZbtQuery
{
    const url = 'https://openapi.cs2dt.com';

    public static function queryPriceBathName($marketHashNameList){

        $path='/v1/product/price/info?app-key=34403a47c76cef0079267ce7ef9354b0&language=zh_CN';
        $postData=[];
        $postData['appId'] = 730;
        $postData['marketHashNameList'] = $marketHashNameList;
        $result=\App\Lib\Library\RequestLibrary::requestPostResultJsonData(static::url.$path,$postData);
        if($result['success']!=1){
            throw new \ErrorException('Zbt请求错误:'.json_encode($result));
        }
        return array_column($result['data'],null,'itemId');
    }

    public static function queryGoodsSearch($page){
        $path='/v1/product/v2/search';
        $httpQuery = [
            'app-key'  => \Hyperf\Support\env('ZBT_APP_KEY','34403a47c76cef0079267ce7ef9354b0'),
            'appId'    => 730,
            'language' => 'zh_CN',
        ];
        $header = [
            'Content-Type'=>'application/x-www-form-urlencoded'
        ];
        $httpQuery['page']=$page;
        $httpQuery['limit']=100;
        $result=\App\Lib\Library\RequestLibrary::requestGetResultJsonData(static::url.$path,$httpQuery,$header);
        if($result['success']!=1){
            throw new \ErrorException('Zbt请求错误:'.json_encode($result));
        }
        return array_column($result['data']['list'],null,'itemId');
    }
}